package com.qfedu.meidijiaju.controller;

import com.qfedu.meidijiaju.entity.Home;
import com.qfedu.meidijiaju.service.HomeService;
import com.qfedu.meidijiaju.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "家庭表接口")
@RestController
public class HomeController {
    @Autowired
    private HomeService homeService;

    @ApiOperation("查询用户所有家庭信息,需要传递创建人id createUid")
    @RequestMapping(value = "/home/queryHomeInfo",method = RequestMethod.GET)
    public ResponseData<List<Home>> queryHomeInfo(int createUid) {
        ResponseData<List<Home>> responseData = new ResponseData<>();
        List<Home> result = homeService.queryHomeInfo(createUid);

        if (result  != null) {
            responseData.setCode(0);
            responseData.setData(result);
        }

        return responseData;
    }


    @ApiOperation("查询用户当前家庭，需要传递用户id，用户房间名称name")
    @RequestMapping(value = "/home/queryCurrentHome",method = RequestMethod.GET)
    public ResponseData<Home> queryCurrentHome(Home home) {
        ResponseData<Home> responseData = new ResponseData<>();
        Home result = homeService.queryCurrentHome(home);

        if (result != null) {
            responseData.setCode(0);
            responseData.setData(result);
        }

        return responseData;
    }


    @ApiOperation("添加房间信息")
    @RequestMapping(value = "/home/addHome",method = RequestMethod.GET)
    public ResponseData<String> addHome(Home home) {
        ResponseData<String> responseData = new ResponseData<>();
        boolean result = homeService.addHome(home);

        if (result) {
            responseData.setCode(0);
            responseData.setMsg("添加成功");
        }

        return responseData;
    }

    @ApiOperation("删除房间，需要传递房间名name，创建人的id createUid")
    @RequestMapping(value = "/home/deletHome",method = RequestMethod.GET)
    public ResponseData<String> deleteHome(Home home) {
        ResponseData<String> responseData = new ResponseData<>();
        boolean result = homeService.deleteHome(home);

        if (result) {
            responseData.setCode(0);
            responseData.setMsg("删除成功");
        }

        return responseData;
    }


    @ApiOperation("更新当前房间信息")
    @RequestMapping(value = "/home/updateHomeInfo",method = RequestMethod.GET)
    public ResponseData<String> updateHomeInfo(Home home) {
        ResponseData<String> responseData = new ResponseData<>();
        boolean result = homeService.updateHomeInfo(home);

        if (result) {
            responseData.setCode(0);
            responseData.setMsg("更新成功");
        }

        return responseData;
    }
}
